package org.example.dingtalkintegrationservice.pojo.log;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.Signature;
import org.example.dingtalkintegrationservice.pojo.converter.MapConverter;
import org.slf4j.MDC;


import java.time.Instant;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author pc
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Slf4j
@Table(name = "execute_method_log")
@Entity
public class ExecuteMethodLog {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Integer id;
    @Column
    String method;
    @Column
    LocalDateTime startAt;
    @Column
    LocalDateTime endAt;
    @Column
    Long duration;
    @Column
    String state;
    @Column
    String errorLocation;
//    @Lob
    @Column(columnDefinition = "text")
    String errorMsg;
//    @Lob
    @Column(columnDefinition = "text")
    String errorCause;
    @Column
    String errorClass;
    @Column
    String requestId;
//    @Lob
    @Column(columnDefinition = "text")
    @Convert(converter = MapConverter.class)
    Map<String,Object> input=new HashMap<>();
//    @Lob
    @Column(columnDefinition = "text")
    String output;
    @Column
    private Instant createTime;
    @PrePersist
    protected void onCreate() {
        this.createTime = Instant.now();
        this.requestId= MDC.get("requestId");
    }
}